<template>
  <div class="app-container">
    <div class="configure_head">
      <span>配置基本信息</span>
    </div>
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      :label-width="labelWidth"
      class="demo-ruleForm"
    >
      <el-form-item label="卡功能" prop="functionType" :required="true">
        <el-select
          v-model="ruleForm.functionType"
          filterable
          placeholder="请选择"
          clearable
          size="small"
          :style="{ width: inputWidth }"
          :disabled="type == 'watch' || type == 'update' ? true : false"
        >
          <el-option
            v-for="dict in cardFunctionOptions"
            :key="dict.id"
            :label="dict.value"
            :value="dict.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="发行方" prop="merchantId" :required="true">
        <el-select
          v-model="ruleForm.merchantId"
          filterable
          placeholder="请选择"
          clearable
          size="small"
          :style="{ width: inputWidth }"
          ref="merchantRef"
          :disabled="type == 'watch' || type == 'update' ? true : false"
        >
          <el-option
            v-for="dict in merchantOption"
            :key="dict.id"
            :label="dict.name"
            :value="dict.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="卡名称" prop="cardName">
        <el-input
          v-model="ruleForm.cardName"
          placeholder="请输入卡名称"
          maxlength="20"
          :style="{ width: inputWidth }"
          :disabled="type == 'watch' || type == 'update' ? true : false"
        >
        </el-input>
      </el-form-item>
      <el-form-item label="售价" prop="price">
        <el-input
          v-model="ruleForm.price"
          placeholder="0.1~99999"
          :style="{ width: inputWidth }"
          :disabled="type == 'watch' || type == 'update' ? true : false"
        >
          <template slot="append">元</template>
        </el-input>
      </el-form-item>
      <el-form-item label="发行数量" prop="issueTotal" :required="true">
        <el-input
          v-model.number="ruleForm.issueTotal"
          placeholder="1~99999"
          :style="{ width: inputWidth }"
          :disabled="type == 'watch' || type == 'update' ? true : false"
        >
          <template slot="append">张</template>
        </el-input>
      </el-form-item>
      <el-form-item :label="cradImgLabel" prop="cover" ref="cradImgRef">
        <ImageUploadMore
          :limit="1"
          :fileSize="20"
          :disabled="type == 'watch' || type == 'update' ? true : false"
          @successImg="getCradImg"
          :value="ruleForm.cover"
        >
        </ImageUploadMore>
      </el-form-item>
      <el-form-item
        :label="cardIntroduceLabel"
        prop="cardImgList"
        ref="cardIntroduceRef"
      >
        <ImageUploadMore
          :limit="6"
          :fileSize="20"
          @successImg="getCardIntroduce"
          :value="ruleForm.cardImgList"
          :disabled="type == 'watch' ? true : false"
        >
        </ImageUploadMore>
      </el-form-item>
      <template v-if="ruleForm.functionType == 2">
        <el-form-item
          label="是否启用勋章激励"
          prop="stimulateSwitch"
          :required="true"
        >
          <el-switch
            v-model="ruleForm.stimulateSwitch"
            :active-value="'2'"
            :inactive-value="'1'"
            active-text="启用"
            inactive-text="禁用"
          >
          </el-switch>
        </el-form-item>
        <el-form-item
          label="勋章激励值"
          prop="stimulate"
          v-if="ruleForm.stimulateSwitch == '2'"
        >
          <el-input
            v-model="ruleForm.stimulate"
            placeholder="请输入勋章激励值"
            :style="{ width: inputWidth }"
          >
            <template slot="append">%</template>
          </el-input>
        </el-form-item>
      </template>
      <el-form-item
        label="权益发放"
        prop="equityIssueStatus"
        :required="true"
        v-if="ruleForm.functionType == 1"
      >
        <el-switch
          v-model="ruleForm.equityIssueStatus"
          :active-value="'1'"
          :inactive-value="'2'"
          active-text="启用权益发放功能"
          inactive-text="禁用权益发放功能"
        >
        </el-switch>
      </el-form-item>
      <el-form-item label="NFR算力" prop="hashRate" required>
        <el-input
          v-model="ruleForm.hashRate"
          placeholder="请输入NFR算力"
          :style="{ width: inputWidth }"
          :disabled="type == 'watch' || type == 'update' ? true : false"
        >
        </el-input>
      </el-form-item>
      <el-form-item label="自定义标签" prop="" :key="20">
        <el-select
          v-model="ruleForm.tagList"
          multiple
          placeholder="请选择标签"
          filterable
          clearable
          :style="{ width: inputWidth }"
          :disabled="type == 'watch' ? true : false"
        >
          <el-option
            v-for="(item, index) in labelOption"
            :key="index"
            :label="item.value"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <!-- 配置权益 -->
      <!-- <div class="configure">
        <div class="configure_head">
          <div>
            <span v-if="type!='watch'">配置权益</span>
            <span v-if="type=='watch'">门店权益</span>
            <el-button type="primary" size="small" @click="handleView(1)" v-if="type!='watch'">新增门店权益</el-button>
          </div>
          <el-button type="warning" plain icon="el-icon-download" size="mini" :loading="exportLoading"
            @click="handleExport" v-if="type=='watch'">导出</el-button>
        </div>
        <el-table v-loading="loading" element-loading-text="加载中" element-loading-spinner="el-icon-loading"
          element-loading-background="rgba(0, 0, 0, 0.5)" :data="transformData" stripe border>
          <el-table-column label="序号" align="center" type="index" width="64px" />
          <el-table-column label="门店名称" align="center" prop="shopName" :show-overflow-tooltip="true" />
          <template v-for="(col,indexs) in tableHeader">
            <el-table-column :prop="col.prop" :label="col.label" :key="indexs"></el-table-column>
          </template>
          <el-table-column label="操作" align="center" width="120" class-name="small-padding fixed-width"
            v-if="type!='watch'">
            <template slot-scope="scope">
              <el-button size="mini" type="text" @click="editClick(scope.row)" v-if="type!='watch'">编辑</el-button>
              <el-button size="mini" type="text" @click="deleteClick(scope)" v-if="type!='watch'">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div> -->
      <!-- 权益更新说明 -->
      <div v-if="activities.length != 0">
        <div class="configure_head">
          <span>权益更新说明</span>
        </div>
        <el-timeline>
          <el-timeline-item
            v-for="(activity, index) in activities"
            :key="index"
            :timestamp="activity.timestamp"
          >
            <span class="margin_right">{{ activity.operatorTime }}</span>
            <span class="margin_right">{{ activity.operatorName }}</span>
            <span class="margin_right">{{ activity.operatorType }}</span>
            <span class="margin_right">{{ activity.shopName }}</span>
            <span>{{ activity.operatorMessage }}</span>
          </el-timeline-item>
        </el-timeline>
      </div>
      <!-- 操作 -->
      <el-form-item>
        <div class="buttonBox" v-if="type != 'watch'">
          <el-button @click="submitForm('ruleForm', 1)" v-if="type != 'update'"
            >存为草稿</el-button
          >
          <el-button type="info" v-if="type != 'update'" @click="returnList"
            >取消</el-button
          >
          <el-button
            type="primary"
            @click="submitForm('ruleForm', 2)"
            v-if="type != 'update'"
            >铸造</el-button
          >
          <!-- <el-button @click="resetForm('ruleForm')">重置</el-button> -->
        </div>
        <div class="buttonBox" v-if="type == 'update'">
          <el-button type="primary" @click="submitForm('ruleForm', 2)"
            >更新权益合约</el-button
          >
          <el-button type="info" @click="returnList">取消</el-button>
        </div>
      </el-form-item>
    </el-form>
    <!-- 铸造弹窗提示 -->
    <el-dialog
      title=""
      :visible.sync="dialogVisible"
      width="500px"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :show-close="false"
      @close="closeDialog"
    >
      <div class="title_box">
        {{ title }}
        <span
          class="el-icon-success"
          style="color: #13ce66"
          v-if="castingStauts == 1"
        ></span>
        <span
          class="el-icon-warning"
          style="color: red"
          v-if="castingStauts == 2"
        ></span>
      </div>
      <el-progress :percentage="percentage"></el-progress>
      <p v-if="second != 0">正在请求权限，大约剩余{{ second }}s</p>
      <p v-if="castingStauts == 1 && chainAddress">
        交易哈希：{{ chainAddress }}
      </p>
      <p v-if="castingStauts == 2">{{ msg }}</p>
      <span slot="footer" class="dialog-footer">
        <el-button
          @click="dialogVisible = false"
          size="small"
          v-if="castingStauts == 2"
          >关 闭</el-button
        >
        <el-button
          type="primary"
          size="small"
          @click="returnList"
          v-if="castingStauts == 1"
          >返回列表</el-button
        >
        <el-button
          type="primary"
          size="small"
          v-if="castingStauts == 2 && this.type != 'update'"
          @click="submitForm('ruleForm', 1)"
          >保存为草稿，稍后再试
        </el-button>
        <el-button
          type=""
          size="small"
          v-if="castingStauts == 2"
          @click="submitForm('ruleForm', 2)"
          >重 试</el-button
        >
      </span>
    </el-dialog>
    <Dialog ref="dialog" @getLs="getLs" :shopIdList="shopIdList"></Dialog>
    <DialogTwo @getLs="getLs" ref="dialogTwo"></DialogTwo>
  </div>
</template>
<script>
import {
  changeSetup,
  cardShopList,
  issuerSelectList,
  addEquityCard,
  getEquityCard,
  updateEquityCard,
  updateEquityCardSetup,
  exportEquityCard,
  tagSelect,
} from "@/api/equityManager/equityCard";
import Dialog from "@/views/equityManager/equityCardDetail/dialog";
import DialogTwo from "@/views/equityManager/equityCardDetail/dialogTwo";
export default {
  dicts: ["equity_card_issue_type"],
  components: {
    Dialog,
    DialogTwo,
  },
  data() {
    //发行方校验
    // var checkMerchantId = (rule, value, callback) => {
    //   console.log(value)
    //   this.ruleForm.merchantId = value.id
    //   if (!value.id && value.name != '平台-海南炎煌纵横科技有限公司') {
    //     return callback(new Error('请选择发行方'));
    //   } else {
    //     callback();
    //   }
    // };
    //售价校验
    var checkPrice = (rule, value, callback) => {
      var reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/;
      if (!value) {
        return callback(new Error("请填写售价"));
      } else if (value < 0.1 || value > 99999) {
        return callback(new Error("请输入0.1-99999"));
      } else if (!reg.test(value)) {
        return callback(new Error("请输入正确数值"));
      } else {
        callback();
      }
    };
    //发行数量校验
    var checkIssueTotal = (rule, value, callback) => {
      var reg = /^[1-9]\d*$/;
      if (!value) {
        return callback(new Error("请填写发行数量"));
      } else if (value < 1 || value > 99999) {
        return callback(new Error("请输入1-99999"));
      } else if (!reg.test(value)) {
        return callback(new Error("请输入正确数值"));
      } else {
        callback();
      }
    };
    var checkHashRate = (rule, value, callback) => {
      var reg = /(^[0-9](\d+)?(\.\d{1,1})?$)|(^\d\.\d{1,1}$)/;
      if (reg.test(value) == false) {
        return callback(
          new Error("请输入NFR算力（大于等于0且最多保留一位小数）")
        );
      } else {
        callback();
      }
    };
    var checkStimulate = (rule, value, callback) => {
      var reg = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;
      if (reg.test(value) == false || value == "0.00" || value == "0.0") {
        return callback(
          new Error("请输入勋章激励值（大于0且最多保留两位小数）")
        );
      } else {
        callback();
      }
    };
    return {
      exportLoading: false,
      loading: false,
      labelWidth: "140px",
      inputWidth: "300px",
      labelOption: [],
      labelList: [],
      castingStauts: 0, //0铸造中，1铸造成功，2铸造失败
      second: 5, //秒数
      title: "正在铸造", //
      dialogVisible: false,
      percentage: 0, //铸造进度
      progress: "",
      id: "",
      activities: [], //权益更新说明数组
      merchantOption: [], //发行方列表
      shopIdList: [], //排除门店id
      transformData: [], // 获取到的表格数据
      tableHeader: [], // 表头数据
      cradImgLabel: "卡图（0/1）",
      cardIntroduceLabel: "卡介绍（0/6）",
      cradImgLs: [], //卡图数组
      cardIntroduceLs: [], //卡介绍数组
      ruleForm: {
        merchantObj: "",
        cardName: "", //卡名称
        merchantId: "", //发行方商家id 【空为平台】
        cover: "", //卡图
        cardImgList: "", //卡介绍图片
        issueTotal: "", //发行数量
        price: "", //售价
        shopSetup: {
          //shopSetup
          deleteList: [], //删除权益配置（传门店id）
          modifyList: [
            {
              //修改的权益配置（包括新增）
              setupList: [
                {
                  discountLimit: 0,
                  discountMoney: 0,
                  equityType: "",
                  levelId: 0,
                  levelName: "",
                },
              ],
              shopId: 0,
              shopName: "",
              status: '', //状态 1 草稿 2 已上链
              functionType: '', //卡功能类型 1 联名ip权益卡
              equityIssueStatus: '2', //权益发放状态（1开始 2 关闭）
              hashRate: '', //算力
              tagList: [], //自定义标签数组
              stimulateSwitch: '1', //激励值开关 1关闭 2开启
              stimulate: '', //激励值
            },
          ],
        },
        status: "", //状态 1 草稿 2 已上链
        functionType: "", //卡功能类型 1 联名ip权益卡
        equityIssueStatus: "2", //权益发放状态（1开始 2 关闭）
        hashRate: "", //算力
        tagList: [], //自定义标签数组
        stimulateSwitch: "1", //激励值开关 1关闭 2开启
        stimulate: "", //激励值
      },
      fromLs: [],
      rules: {
        cardName: [
          {
            required: true,
            message: "请输入卡名称",
            trigger: ["blur", "change"],
          },
        ],
        // price: [{
        //   required: true,
        //   message: '请填写售价',
        //   trigger: ['blur', 'change']
        // }, ],
        price: [
          {
            required: true,
            validator: checkPrice,
            trigger: ["blur", "change"],
          },
        ],
        issueTotal: [
          {
            validator: checkIssueTotal,
            trigger: ["blur", "change"],
          },
        ],
        merchantId: [
          {
            required: true,
            message: "请选择发行方",
            // validator: checkMerchantId,
            trigger: "change",
          },
        ],
        cover: [
          {
            required: true,
            message: "请上传卡图",
            trigger: ["blur", "change"],
          },
        ],
        cardImgList: [
          {
            required: true,
            message: "请上传卡介绍图片",
            trigger: ["blur", "change"],
          },
        ],
        functionType: [
          {
            required: true,
            message: "请选择卡功能",
            trigger: "change",
          },
        ],
        hashRate: [
          {
            // required: true,
            // message: '请输入NFR算力',
            validator: checkHashRate,
            trigger: ["blur", "change"],
          },
        ],
        stimulate: [
          {
            required: true,
            validator: checkStimulate,
            trigger: ["blur", "change"],
          },
        ],
      },
      msg: "", //失败原因
      deleteList: [], //删除id数组
      chainAddress: "", //区块链地址
      type: "", // add:新增，edit: 编辑，update：更新权益，watch: 查看
      cardFunctionOptions: [],
    };
  },
  created() {
    this.type = this.$route.query.type;
    this.id = this.$route.query.id;
    this.getCardDict();
    this.getTagSelect();
    this.getMerchantList();
    // this.getCardShopList()
    if (this.id) {
      this.getEquityCard();
    }
  },
  methods: {
    //获取卡功能字典
    getCardDict() {
      var dictType = "equity_function_type";
      this.$getSelectList(dictType)
        .then((res) => {
          this.cardFunctionOptions = res.result[0].dictList;
        })
        .finally(() => {});
    },
    //查询自定义标签下拉框
    getTagSelect() {
      tagSelect().then((res) => {
        this.labelOption = res.result;
      });
    },
    //获取数字权益卡详细信息
    getEquityCard() {
      getEquityCard(this.id)
        .then((res) => {
          this.ruleForm.cardName = res.result.cardName;
          this.ruleForm.merchantId = res.result.merchantId;
          this.ruleForm.functionType = res.result.functionType;
          this.ruleForm.equityIssueStatus = res.result.equityIssueStatus;
          // let merchantName = res.result.name
          // if (res.result.merchantId == null || res.result.merchantId == '') {
          //   merchantName = '平台-海南炎煌纵横科技有限公司'
          //   console.log(merchantName)
          // }else{
          //   merchantName = res.result.name
          // }
          // this.ruleForm.merchantObj = {
          //   merchantId: res.result.merchantId,
          //   merchantName: merchantName
          // }
          // console.log(this.ruleForm.merchantObj)
          this.ruleForm.price = res.result.price;
          this.ruleForm.issueTotal = res.result.issueTotal;
          this.ruleForm.cover = res.result.cover;
          this.cradImgLabel = "卡图（1/1）";
          this.ruleForm.cardImgList = res.result.cardImgList;
          this.cardIntroduceLabel =
            "卡介绍" + "（" + res.result.cardImgList.length + "/6" + "）";
          this.activities = res.result.cardLogList;
          this.ruleForm.shopSetup.modifyList = res.result.setupList;
          this.fromLs = res.result.setupList;
          this.ruleForm.hashRate = res.result.hashRate;
          this.ruleForm.tagList = res.result.tagList;
          this.ruleForm.stimulateSwitch = res.result.stimulateSwitch;
          this.ruleForm.stimulate = res.result.stimulate;
        })
        .catch(() => {});
    },
    deteleObject(obj) {
      //去除数组重复对象
      var uniques = [];
      var stringify = {};
      for (var i = 0; i < obj.length; i++) {
        var keys = Object.keys(obj[i]);
        keys.sort(function (a, b) {
          return Number(a) - Number(b);
        });
        var str = "";
        for (var j = 0; j < keys.length; j++) {
          str += JSON.stringify(keys[j]);
          str += JSON.stringify(obj[i][keys[j]]);
        }
        if (!stringify.hasOwnProperty(str)) {
          uniques.push(obj[i]);
          stringify[str] = true;
        }
      }
      uniques = uniques;
      return uniques;
    },
    //获取发行方列表
    getMerchantList() {
      let data = {};
      issuerSelectList(data)
        .then((res) => {
          this.merchantOption = res.result;
        })
        .catch(() => {});
      // .finally(() => {

      // });
    },
    //获取权益表头
    getCardShopList() {
      this.loading = true;
      let headList = [];
      let data = {
        id: this.id,
      };
      cardShopList(data)
        .then((res) => {
          this.loading = false;
          res.data.levelColumnList.forEach((item, index) => {
            var obj = {};
            obj.label = "用户等级" + item;
            obj.prop = "level" + index;
            headList.push(obj);
          });
          this.tableHeader = headList;
          if (this.id) {
            this.transformData = res.data.shopList;
            //过滤已选过的店铺
            this.shopIdList = [];
            this.transformData.forEach((item) => {
              this.shopIdList.push(item.shopId);
            });
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    // 获取权益列表
    getLs(e, type) {
      console.log(type);
      let ls = this.fromLs.concat(e);
      this.fromLs = this.deteleObject(ls);
      console.log("this.fromLs--", this.fromLs);
      this.loading = true;
      let data = {
        list: e,
      };
      changeSetup(data)
        .then((res) => {
          // this.transformData = res.data
          let list = res.data;
          if (type == 2) {
            this.transformData = list;
          } else {
            this.transformData = this.transformData.concat(list);
          }
          console.log("this.transformData", this.transformData);
          //过滤已选过的店铺
          this.shopIdList = [];
          this.transformData.forEach((item) => {
            this.shopIdList.push(item.shopId);
          });
          console.log("this.shopIdList", this.shopIdList);
          this.loading = false;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    /** 卡图 */
    getCradImg(e) {
      this.cradImgLs = e.split(",");
      console.log(this.cradImgLs, this.cradImgLs.length);
      let length = 0;
      if (this.cradImgLs[0] == "") {
        length = 0;
      } else {
        length = this.cradImgLs.length;
      }
      this.cradImgLabel = "卡图" + "（" + length + "/1" + "）";
      this.ruleForm.cover = e;
      this.$refs["cradImgRef"].clearValidate();
    },
    /** 卡介绍 */
    getCardIntroduce(e) {
      if (e != "") {
        this.cardIntroduceLs = e.split(",");
      } else {
        this.cardIntroduceLs = [];
      }
      console.log(this.cardIntroduceLs, this.cardIntroduceLs.length);
      let length = 0;
      if (this.cardIntroduceLs[0] == "") {
        length = 0;
      } else {
        length = this.cardIntroduceLs.length;
      }
      this.cardIntroduceLabel = "卡介绍" + "（" + length + "/6" + "）";
      this.ruleForm.cardImgList = this.cardIntroduceLs;
      this.$refs["cardIntroduceRef"].clearValidate();
    },
    /** 配置权益表单编辑 */
    editClick(e) {
      console.log(e.shopId);
      this.$refs.dialogTwo.open(this.fromLs, e.shopId);
    },
    /** 配置权益表单删除 */
    deleteClick(e) {
      console.log(e.row.shopId);
      this.deleteList.push(e.row.shopId);
      this.deleteList = this.deteleObject(this.deleteList);
      this.fromLs.splice(e.$index, 1);
      this.transformData.splice(e.$index, 1);
      this.shopIdList.splice(e.$index, 1);
      console.log("删除后", this.fromLs);
      console.log("删除后", this.transformData);
      console.log("删除后", this.shopIdList);
    },
    /** 新增门店权益按钮操作 */
    handleView(row) {
      this.$refs.dialog.open(row, false);
    },
    /** 删除重复的删除权益配置（传门店id） */
    deleteArr(arrObj, arr) {
      arrObj.forEach((item, index1) => {
        arr.forEach((items, index2) => {
          if (item.shopId == items) {
            console.log(index2);
            arr.splice(index2, 1);
          }
        });
      });
      console.log(arr);
      return arr;
    },
    /** 铸造 */
    submitForm(formName, status) {
      this.ruleForm.status = status;
      console.log(this.ruleForm);
      //  return
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // alert('submit!');
          // if (this.fromLs.length == 0) {
          //   this.$message.error('请配置门店权益');
          //   return
          // }
          this.dialogVisible = true;
          this.getSetInterval();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    getSetInterval() {
      //进度更新
      this.title = "铸造中";
      this.castingStauts = 0;
      this.percentage = 0;
      this.second = 5;
      this.progress = setInterval(() => {
        this.second--;
        this.percentage = this.percentage + 20;
        console.log(this.percentage);
        if (this.percentage == 20) {
          //请求上传接口
          // this.ruleForm.shopSetup.deleteList = this.deleteList
          this.ruleForm.shopSetup.deleteList = this.deleteArr(
            this.fromLs,
            this.deleteList
          );
          this.ruleForm.shopSetup.modifyList = this.fromLs;
          if (this.id && this.type != "update") {
            //修改
            var data = {
              ...this.ruleForm,
              id: this.id,
            };
            updateEquityCard(data)
              .then((res) => {
                // this.chainAddress = res.data
                this.chainAddress = res.result;
                this.percentage = 100;
                this.second = 0;
                if (this.ruleForm.status == 1) {
                  this.title = "存为草稿成功";
                } else {
                  this.title = "铸造成功";
                }
                clearInterval(this.progress);
                this.castingStauts = 1;
              })
              .catch((resx) => {
                this.percentage = 0;
                console.log(resx);
                this.second = 5;
                this.castingStauts = 2;
                this.title = "铸造失败";
                // this.msg = resx.data.msg
                this.msg = resx.message;
                clearInterval(this.progress);
              });
          } else if (this.id && this.type == "update") {
            //更新权益合约
            var data = {
              cardImgList: this.ruleForm.cardImgList,
              id: this.id,
              shopSetup: this.ruleForm.shopSetup,
              equityIssueStatus: this.ruleForm.equityIssueStatus,
              tagList: this.ruleForm.tagList,
              stimulateSwitch: this.ruleForm.stimulateSwitch,
              stimulate: this.ruleForm.stimulate,
            };
            updateEquityCardSetup(data)
              .then((res) => {
                // this.chainAddress = res.data
                this.chainAddress = res.result;
                this.percentage = 100;
                this.second = 0;
                this.title = "更新成功";
                clearInterval(this.progress);
                this.castingStauts = 1;
              })
              .catch((resx) => {
                console.log(resx);
                this.percentage = 0;
                this.second = 5;
                this.castingStauts = 2;
                this.title = "铸造失败";
                // this.msg = resx.data.msg
                this.msg = resx.message;
                clearInterval(this.progress);
              });
          } else {
            //新增
            var data = {
              ...this.ruleForm,
            };
            addEquityCard(data)
              .then((res) => {
                // this.chainAddress = res.data
                this.chainAddress = res.result;
                this.percentage = 100;
                this.second = 0;
                if (this.ruleForm.status == 1) {
                  this.title = "存为草稿成功";
                } else {
                  this.title = "铸造成功";
                }
                clearInterval(this.progress);
                this.castingStauts = 1;
              })
              .catch((resx) => {
                console.log(resx);
                this.percentage = 0;
                this.second = 5;
                this.castingStauts = 2;
                this.title = "铸造失败";
                // this.msg = resx.data.msg
                this.msg = resx.message;
                clearInterval(this.progress);
              });
          }
        } else if (this.percentage == 100) {
          this.percentage == 100;
          clearInterval(this.progress);
        }
      }, 1000);
    },
    returnList() {
      //返回列表
      this.$router.push({
        path: "equityCard",
        query: {},
      });
    },
    closeDialog() {
      //监听关闭弹窗事件
      this.percentage = 0;
      this.second = 5;
      clearInterval(this.progress);
      console.log("关闭弹窗");
    },
    /** 重置 */
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = {
        id: this.id,
      };
      this.$modal
        .confirm("是否确认导出数据？")
        .then(() => {
          this.exportLoading = true;
          return exportEquityCard(queryParams);
        })
        .then((response) => {
          this.$download.name(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>
<style scoped>
.app-container {
  background: #fff;
  margin: 20px;
  border-radius: 8px;
}

.main {
  padding: 20px 0;
}

.configure {
  padding: 20px 0 30px;
}

.configure_head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: bold;
  font-size: 20px;
  color: #444;
  margin-bottom: 20px;
}

.configure_head span {
  margin-right: 20px;
}

.buttonBox {
  padding-top: 20px;
  display: flex;
  justify-content: center;
}

.title_box {
  font-size: 18px;
  color: #606266;
  margin-bottom: 20px;
}

::v-deep .el-dialog__header {
  padding: 0;
  margin: 0;
}

.margin_right {
  margin-right: 10px;
}
</style>
